<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>巡检任务管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script type="text/javascript" src="../../js/jquery-2.0.3.min.js"></script>
</head>
<body>
<div style="padding: 20px;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <form class="layui-form" action="" style="margin-top: 30px; margin-left: -20px">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 90px;">任务编号：</label>
                            <div class="layui-input-inline" style="width: 170px">
                                <select name="task_id" id="task_id"  lay-filter="xmFilter">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 90px;">线路编号：</label>
                            <div class="layui-input-inline" style="width: 170px">
                                <select name="line_number" id="line_number" lay-filter="xmFilter">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 90px;">任务状态：</label>
                            <div class="layui-input-inline" style="width: 170px">
                                <select name="state_name" id="state_name"  lay-filter="xmFilter">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="button" id="search_inspe" class="layui-btn" lay-submit="search_inspe" lay-filter="search_inspe" style="margin-left: 30px">查询</button>
                        </div>

                        <div class="layui-inline">
                            <button type="button" id="add_inspetion" lay-event="add_inspetion" class="layui-btn" style="margin-left: 30px">
                                <i class="layui-icon"></i>制定巡检任务</button>
                        </div>

                    </form>


                </div>
            </div>
        </div>
    </div>

    <table class="layui-hide" id="Inspe_table" lay-filter="Inspe_table"></table>

</div>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit_inspe">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">取消</a>
    <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
    <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="show">查看</a>-->
</script>



<script>
    layui.use(['table','form', 'layedit', 'laydate'], function(){
        var table = layui.table
            ,form = layui.form
            ,layer = layui.layer
            ,laydate = layui.laydate;

        form.render("select");
        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：https://www.layui.com/doc/modules/table.html#totalRow
        table.render({
            elem: '#Inspe_table'
            ,url:'/QueryListInspection.do'
            ,toolbar: '#toolbarDemo'
            ,title: '巡检信息表'
            ,totalRow: true
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'task_id', title:'任务编号',width:110}
                ,{field:'task_name', title:'任务名称',width:120}
                ,{field:'line_name', title:'巡检线路',width:100}
                ,{field:'start_tower', title:'起始杆号',width:100}
                ,{field:'stop_tower', title:'终止杆号',width:100}
                ,{field:'user_name', title:'下发人',width:80}
                ,{field:'lssue_time', title:'下发时间',width:100}
                ,{field:'state_name', title:'任务状态',templet: ZhuangTai,width:100}
                ,{field:'completion_time', title:'任务完成时间',width:120}
                ,{field:'yesno_name', title:'任务是否取消',width:120}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
            ]]
            ,page:{
                limits:[5,10,15,20]
            }
        });
        function ZhuangTai(data) {
            var state_name = data.state_name;
            var btns="";
            if (state_name=="已完成"){
                btns+='<a class=""style="color:#19b8ed">已完成</a>'
            }
            if (state_name=="执行中"){
                btns+='<a class=""style="color:#ed0e26">执行中</a>'
            }
            if (state_name=="已分配"){
                btns+='<a class=""style="color:#8f9ded">已分配</a>'
            }
            if (state_name=="待分配"){
                btns+='<a class=""style="color:#82ed35">待分配</a>'
            }
            return btns;
        }

       //查询
        $("#search_inspe").click(function () {
//            alert("点击查询成功")
            var task_id = $("select[name=task_id]").val();            //获取任务编号
            var line_number = $("select[name=line_number]").val();   //获取线路编号
            var state_name = $("select[name=state_name]").val();   //获取线路编号
            table.reload('Inspe_table', {
                url: '/SearchInspection.do',
                method: "get",
                where: {task_id: task_id, line_number: line_number,state_name:state_name}//设定异步数据接口的额定参数
            });
        });



        //动态给搜索线路框select中option添加线路内容
        $.ajax({
            url:"/showSelectLine.do",
            data:{},
            dataType:"json",
            type: 'post',
            success: function (data) {
//                   console.log(data);//下面会提到这个data是什么值
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    $('#line_number').append(new Option(value.line_number,value.line_number));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });

        //动态给搜索任务框select中option添加任务信息内容
        $.ajax({
            url:"/ShowSelectInspection.do",
            data:{},
            dataType:"json",
            type: 'post',
            success: function (data) {
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    $('#task_id').append(new Option(value.task_id,value.task_id));// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });

        //动态给搜索任务状态框select中option添加任务状态信息内容
        $.ajax({
            url:"/ShowSelectState.do",
            data:{},
            dataType:"json",
            type: 'post',
            success: function (data) {
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    if (value.state_id>4 && value.state_id<9){
                        $('#state_name').append(new Option(value.state_name,value.state_id));// 下拉菜单里添加元素
                    }
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        });

        //日期
        laydate.render({
            elem: '#date'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#date1'
            ,type: 'datetime'
        });

        //监听行工具事件
        table.on('tool(Inspe_table)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                if (data.task_state==5 || data.task_state==8){
                    layer.confirm('真的取消行么', function(index){
                        $.ajax({
                            url:"/DeleteInpetion.do",


                        })
                        obj.del();
                        layer.close(index);
                    });
                }else if (data.task_state==6){
                    layer.msg('任务已在执行中，不可取消');
                }else if (data.task_state==7){
                    layer.msg('任务已完成，不可取消');
                }

            } else if(obj.event === 'edit_inspe'){
                if (data.task_state==5){
                    layer.msg('任务已分配，不可修改');
                }else if (data.task_state==6){
                    layer.msg('任务已在执行中，不可修改');
                }else if (data.task_state==7){
                    layer.msg('任务已完成，不可修改');
                }else if (data.task_state==8){
                    var index = layer.open({
                        type: 2,
                        title: ['修改巡检信息', 'font-size:13px;background-color: #23262E;color:white;text-algin:center'],
                        shade: [0.7, '#393D49'],
                        area: ['62%', '62%'],
                        closeBtn: 2,
                        shadeClose:-true,
                        content: 'pages/sovle/edit_Inspetion.html',
                        success:function (layero,index) {
                            var body = layer.getChildFrame('body', index);
                            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            //数据回显
                            body.find('input[name=task_id]').val(data.task_id);
                            body.find('input[name=task_name]').val(data.task_name);
                            body.find('select[name=line_name]').val(data.line_name);
                            body.find('input[name=user_name]').val(data.user_name);
                            body.find('input[name=admin]').val(data.admin);
                            body.find('input[name=lssue_time]').val(data.lssue_time);
                            body.find('textarea[name=task_des]').val(data.task_des);
                        },end:function () {
                            table.reload('Inspe_table',{
                                where:{
                                    key:{
                                        time:new Date()
                                    }
                                }
                            },'data');
                        }
                    });
                }
            }else if(obj.event === 'show'){
//                alert("查看按钮点击成功！！")
//                alert("线路编号为："+data.line_number+"   下发时间为："+data.lssue_time+"   杆塔号："+data.start_tower)
                var index = layer.open({
                    type: 2,
                    title: ['查看巡检任务', 'font-size:13px;background-color: #23262E;color:white;text-algin:center'],
                    shade: [0.7, '#393D49'],
                    area: ['62%', '62%'],
                    closeBtn: 2,
                    shadeClose:-true,
                    content: 'pages/sovle/Show_InspetionLine.html',
                    success:function (layero,index) {
                        var body = layer.getChildFrame('body', index);
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        //数据回显
                        body.find('input[name=task_id]').val(data.task_id);
                        body.find('input[name=task_name]').val(data.task_name);
                        body.find('input[name=line_name]').val(data.line_name);
                        body.find('input[name=line_number]').val(data.line_number);
                        body.find('input[name=user_name]').val(data.user_name);
                        body.find('input[name=state_name]').val(data.state_name);
                        body.find('input[name=completion_time]').val(data.completion_time);
                        body.find('input[name=start_tower]').val(data.start_tower);
                        body.find('input[name=stop_tower]').val(data.stop_tower);
                        body.find('textarea[name=task_des]').val(data.task_des);
                        body.find('input[name=lssue_time]').val(data.lssue_time);

                    }
                });
            }
        });
//        工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选')
                    break;
            };
        });
    });
</script>


<!--加按钮点击事件-->
<script>

    $(document).on('click',"#add_inspetion",function () {
        var user=JSON.parse(sessionStorage.getItem("users"));
//        alert("添加按钮点击成功"+user[0].user_account);
        var index = layer.open({
            type: 2,
            title: ['巡检信息信息添加', 'font-size:13px;background-color: #23262E;color:white;text-algin:center'],
            shade: [0.7, '#393D49'],
            area: ['62%', '62%'],
            closeBtn: 2,
            id:'addsovle',
            shadeClose:true,
            content: 'pages/sovle/add_Inspetion.html',
            success:function (layero,index) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                //数据回显
                body.find('input[name=admin]').val(user[0].user_name);
                body.find('input[name=lineman_account]').val(user[0].user_account);

            },end:function () {
                table.reload('Inspe_table',{
                    where:{
                        key:{
                            time:new Date()
                        }
                    }
                },'data');
            }
        });
    })
</script>





</body>
</html>